package org.yy.controller;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yy.service.UserService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class UserController {

    @Reference
    UserService userService;

    @Value("${msg}")
    String msg;

    @Value("${spring.datasource.url}")
    String datasourceUrl;


    @RequestMapping("/config/viewconfig")
    public String viewconfig() {
        return "msg=" + msg + "\ndatasourceUrl=" + datasourceUrl;
    }

    @RequestMapping("/user/register/{email}/{password}/{code}")
    public Boolean register(@PathVariable String email, @PathVariable String password, @PathVariable String code) {
        return userService.register(email, password, code);
    }

    @RequestMapping("/user/isRegistered/{email}")
    public Boolean isRegistered(@PathVariable String email) {
        return userService.isRegistered(email);
    }

    @RequestMapping("/user/login/{email}/{password}")
    public String login(@PathVariable String email, @PathVariable String password,
                        HttpServletRequest request, HttpServletResponse response) {
        return userService.login(email, password, request, response);
    }

    @RequestMapping("/user/info/{token}")
    public String info(@PathVariable String token) {
        return userService.info(token);
    }

}
